<template>
	<view>
		
		<view class="user-center">
			<button type="default" class="change" @tap="change">修改用户信息</button>
			<view class="item">
				<view class="text">
					头像
				</view>
				<view class="desc">
					<button type="default" class="upload" @tap="upload">上传头像</button>
				</view>
			</view>
			<view class="item">
				<view class="text">
					用户名
				</view>
				<view class="desc" >
					<input type="text" value="" v-model="userObj.username"/>
				</view>
			</view>
			<view class="item">
				<view class="text">
					昵称
				</view>
				<view class="desc">
					
					<input type="text" value="" v-model="userObj.nickname"/>
				</view>
			</view>
			
			<view class="item">
				<view class="text">
					手机号
				</view>
				<view class="desc">
					
					<input type="text" value="" v-model="userObj.phone"/>
				</view>
			</view>
				<button type="default" class="leave" @tap="leave">更新</button>
		</view>
	</view>
</template>

<script>
	import {upLoad} from "../../../utils/mine/upLoad/index.js"
	export default {
		data() {
			return {
				userObj:{}
			};
		},
		onShow() {
			this.userObj=uni.getStorageSync("userList")
		},
		methods:{
			upload(){
				let _self = this;
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: ['album'], //从相册选择
						success: (chooseImageRes) => {
							// console.log(chooseImageRes);
							const tempFilePaths = chooseImageRes.tempFilePaths;
							// console.log(tempFilePaths[0]);
							_self.IMGS = tempFilePaths[0];
							uni.showLoading({
								title:'正在上传'
							});
							const uploadTask = uni.uploadFile({
								url: 'http://leju.bufan.cloud/lejuClient/login/uploadAvatar',
								filePath: tempFilePaths[0],
								name: 'file',
								formData: {
									"user":'test'
								},
								success: (res) => {
									console.log((JSON.parse(res.data)).data.fileUrl);
									uni.hideLoading();
									uni.showToast({
										title:'上传成功',
										icon:'none',
										duration:2000
									});
									uni.setStorageSync('ava', (JSON.parse(res.data)).data.fileUrl);
								},
								fail: (error) => {
									console.log('失败原因',error);
								}
							});
						}
					});
				
			}
			
		}
	}
</script>

<style lang="scss" scoped>
 .change{
	 float: right;
	 margin-top: 20rpx;
	 color: #353535;
	 border: 2rpx solid #353535;
	 background-color: rgba(0,0,0,0);
	 width: 224rpx;
	 height: 60rpx;
	 font-size: 26rpx;
	 line-height: 60rpx;
 }
 .user-center{
	 width: 90%;
	 margin: 0 auto;
	 .item{
		 width: 100%;
		 display: flex;
		 justify-content: space-between;
		 align-items: center;
		 font-size: 32rpx;
		 line-height: 94rpx;
		 box-sizing: border-box;
		 padding: 10rpx 30rpx;
		 border-bottom: 2rpx solid #e5e5e5;
		 .text{
			 color: #494949;
		 }
		 .upload{
			 color: #353535;
			 border: 2rpx solid #353535;
			 background-color: rgba(0,0,0,0);
			 height: 60rpx;
			 font-size: 26rpx;
			 line-height: 60rpx;
		 }
	 }
	 .leave{
			position: fixed;
		     left: 50%;
		     bottom: 20%;
		     margin-left: -184rpx;
		     width: 370rpx;
		     height: 88rpx;
		     font-size: 32rpx;
		     color: #fff;
		     text-align: center;
		     line-height: 88rpx;
		     background: #1c4b47;
		     border-radius: 16rpx;
	 }
 }
 input{
	 text-align: right;
 }
</style>
